///////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2009 Summit Contributors.  
// See: http://code.google.com/p/tyemill/wiki/SummitContributors
//
// The name and logo of Summit are trademarks of TYEMILL, LLC - All Rights 
// Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without 
// limitation the rights to use, copy, modify, merge, publish, distribute, 
// sublicense, and/or sell copies of the Software, and to permit persons to 
// whom the Software is furnished to do so, subject to the following 
// conditions:
//
// The above copyright notice and this permission notice shall be included 
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
///////////////////////////////////////////////////////////////////////////////

package summit.basecamp.wrappers
{

import summit.basecamp.constants.BasecampResource;
import summit.basecamp.constants.CommentableType;
import summit.basecamp.helpers.TodoItemHelper;
import summit.data.AccountToken;
import summit.net.BasecampLoader;

/**
 * Wrapper for Basecamp todo-item operations.
 */
public class TodoItemWrapper extends AbstractWrapper implements
ICommentableWrapper, IChildWrapper, IStandardWrapper
{
	/**
	 * @copy ProjectWrapper#ProjectWrapper()
	 */
	public function TodoItemWrapper(token:AccountToken = null,
	loader:BasecampLoader = null)
	{
		super(BasecampResource.TODOITEM, token, loader);
	}
	
	/** Gets a new instance of a <code>TodoListWrapper</code>. **/
	public function get parent():IParentWrapper
	{
		return new TodoListWrapper(null, loader);
	}
	
	/** Returns <code>CommentableType.TODOITEM</code>. **/
	public function get commentableType():String
	{
		return CommentableType.TODOITEM;
	}
	
/**
	 * Marks a todo-item as complete.
	 * 
	 * @param id The id of the todo-item to be marked as complete.
	 */ 
	public function complete(id:String):void
	{
		loader.load(TodoItemHelper.complete(id));
	}
	
	/**
	 * Creates a todo-item.
	 * 
	 * <p>Typically, the XML provided is based on the template returned from
	 * a call to <code>prepare</code>.
	 * 
	 * <p>The XML provided must contain the <code>todo-list-id</code> 
	 * element.</p>
	 * 
	 * <p>Note: The new todo-item is always placed below all other existing 
	 * todo-items (visually).</p>
	 * 
	 * @param content Represents the todo-item to be created.
	 */
	public function create(content:XML):void
	{
		loader.load(TodoItemHelper.create(content));
	}
	
	/**
	 * Deletes a todo-item.
	 * 
	 * @param id The id of the todo-item to be deleted.
	 */
	public function destroy(id:String):void
	{
		loader.load(TodoItemHelper.destroy(id));
	}
	
	/**
	 * Retrieves an existing todo-item from the Basecamp store.
	 * 
	 * <p>The XML returned is pre-filled with the existing values of 
	 * the identified todo-item, and is ready to be resubmitted via the 
	 * <code>update</code> function.</p>
	 * 
	 * @param id The id of the todo-item to be retrieved.
	 * @param projectId The id of the project associated with the todo-item.
	 */ 
	public function edit(id:String, projectId:String):void
	{
		loader.load(TodoItemHelper.edit(id));
	}
	
	/**
	 * Gets a list of todo-items for the specified list.
	 * 
	 * @param todoListId
	 * The id of the todo-list from which todo-items are retrieved. 
	 * @param projectId
	 * The id of the project associated with the todo-list.
	 */
	public function list(todoListId:String, projectId:String):void
	{
		loader.load(TodoItemHelper.list(todoListId));
	}
	
	/**
	 * Gets a template for creating a new todo-item.
	 * 
	 * <p>The template retrieved is used with <code>create</code> to 
	 * submit a new todo-item.</p>
	 * 
	 * @param todolistId The id of the todo-list that is to be associated with
	 * the todo-item when submitted via a call to <code>create</code>.
	 */ 
	public function prepare(todoListId:String):void
	{
		loader.load(TodoItemHelper.prepare(todoListId)); 
	}
	
	/**
	 * Gets a single todo-item.
	 * 
	 * @param id The id of the todo-item to be read.
	 * @param projectId The id of the project associated with the todo-item.
	 */	
	public function read(id:String, projectId:String):void
	{
		loader.load(TodoItemHelper.read(id));
	}
	
	/**
	 * Reorders todo-items.
	 *
	 * <p>Completed items can not be reordered.</p>
	 * 
	 * <p>Items that are not referenced in <code>content</code> are reordered
	 * below those that are referenced.</p>
	 * 
	 * <p>If the <code>todoListId</code> provided does not represent 
	 * the requested list of todo-items, the items are reparented accordingly.
	 * Lists can not be reparented across project bounds.</code></p>
	 * 
	 * @param content The list of items to be reordered.
	 * @param todoListId The id of the todo-list associated with the 
	 * todo-items.
	 */
	public function reorder(content:XML, todoListId:String):void
	{
		loader.load(TodoItemHelper.reorder(content, todoListId));
	}
	
	/**
	 * Marks a todo-item as uncomplete.
	 * 
	 * @param id The id of the todo-item to be marked as uncomplete. 
	 */ 
	public function uncomplete(id:String):void
	{
		loader.load(TodoItemHelper.uncomplete(id));	
	}
	
	/**
	 * Updates an existing todo-item.
	 * 
	 * <p><code>content</code> submitted to <code>update</code> is typically
	 * retrieved from <code>edit</code>.</p>
	 * 
	 * @param content The updated XML content of an existing todo-item.
	 */ 
	public function update(content:XML):void
	{
		loader.load(TodoItemHelper.update(content));
	}
}
}
//////////////////////////////////////////////////////// gmarius@tyemill.com //